﻿<!DOCTYPE HTML>
<html>
{include file="public:header_css"}
<link href="__STATIC__/admin/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<body>

<nav class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 投票管理 <span class="c-gray en">&gt;</span> 编辑活动
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>

<div class="page-container">

	<form action="" method="post" class="form form-horizontal" id="form-shops-add" enctype="multipart/form-data" name="myForm">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$info['title']}" placeholder="" id="title" style="width:60%;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>时间周期：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text Wdate" id="start_time" name="start_time" value="{$info.start_time||date='Y-m-d',###}" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" style="width:24%;"> -
				<input type="text" class="input-text Wdate" id="end_time" name="end_time" value="{$info.end_time||date='Y-m-d',###}" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" style="width:24%;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>活动投票总限制：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$info['vote_limit']}" placeholder="" id="vote_limit" style="width:60%;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>每人投票总限制：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$info['total_limit']}" placeholder="" id="total_limit" style="width:60%;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>每人每日限制：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$info['day_limit']}" placeholder="" id="day_limit" style="width:60%;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片logo：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div  id="checkshow" style="width: 375px;height: 200px;padding: 5px;border: 1px solid #e6e6e6;border-radius: 10px;float:left;">
					<img src="{$info.pic_url}" alt=""  id="ImgPreview" style="width: 100%;height: 100%"/>
				</div>
				<div style="float:left;margin: 170px 0 0 10px;">
					<button class="btn btn-primary radius" type="button"  onclick="$('#fileUpload').click()">选择图片</button>
					<span style="color:#c8a0a0;">建议上传图片为正方形</span>
				</div>
				<input type="file" class="input-text" id="fileUpload" name="pic_url" style="display: none">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">活动介绍：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<script id="editor" type="text/plain">{$info['content']}</script>
            </div>
        </div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input type="hidden" id="id" value="{$info['id']}">
				<button class="btn btn-primary radius" type="submit" id="submit">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
				<a class="btn btn-warning radius" href="{:url('index')}">&nbsp;&nbsp;取消&nbsp;&nbsp;</a>
			</div>
		</div>
	</form>

</div>
{include file="public:footer_js"}


<script type="text/javascript" src="__STATIC__/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript" src="__STATIC__/admin/lib/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__STATIC__/admin/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        var ue = UE.getEditor('editor',{
            toolbars:[
                [
                    'fullscreen','source','|','undo','redo','|',
                    'bold','italic','underline','fontborder','striethrough','superscript','justifyright','justifycenter', 'justifyjustify',
                    'subscript','removeformat','formatmath','autotypeset','blockquote','strikethrough','blockquote','link','emotion',
                    'pasteplain','|','forecolor','backcolor','insertorderedlist','fontsize','fontfamily','justifyleft','unlink','help',
                    'insertunorderedlist','selectall','cleardoc','|',
                    'rowspacingtop','rowspacingbottom','lineheight','|','imagenone','imageleft','imageright',
                    'imagecenter','simpleupload','insertimage','|',
                ]
            ],
        });

        // 图片上传框
        $("#fileUpload").change(function() {
            $('#ImgPreview').show();
            var $file = $(this);
            var fileObj = $file[0];
            var windowURL = window.URL || window.webkitURL;
            var dataURL;
            var $img = $("#ImgPreview");
            if(fileObj && fileObj.files && fileObj.files[0]){
                dataURL = windowURL.createObjectURL(fileObj.files[0]);
                $img.attr('src',dataURL);
            }else{
                dataURL = $file.val();
                var imgObj = document.getElementById("ImgPreview");
                imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
                imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;

            }
        });

        $("#submit").click(function(){

            var id 	        = $("#id").val();
            var title 	    = $("#title").val();
            var start_time  = $("#start_time").val();
            var end_time    = $("#end_time").val();
            var vote_limit  = $("#vote_limit").val();
            var total_limit = $("#total_limit").val();
            var day_limit   = $("#day_limit").val();
            var content     = ue.getContent();
            var pic_url		= document.myForm.pic_url.files[0];

            // 标题
            if(title == ''){
                layer.msg('标题不可为空!',{icon:7,time:1000});
                $("#title").focus();
                return ;
            }

            // 开始时间
            if(start_time == ''){
                layer.msg('开始时间不可为空!',{icon:7,time:1000});
                $("#start_time").focus();
                return ;
            }
            // 结束时间
            if(end_time == ''){
                layer.msg('结束时间不可为空!',{icon:7,time:1000});
                $("#end_time").focus();
                return ;
            }
            // 活动总票数
            if(vote_limit == ''){
                layer.msg('活动总票数不可为空!',{icon:7,time:1000});
                $("#vote_limit").focus();
                return ;
            }
            //图片logo
            if(pic_url == ''){
                layer.msg('图片logo不可为空!',{icon:7,time:1000});
                $("#pic_url").focus();
                return ;
            }
            // 上传数据整理
            var fm = new FormData();
            fm.append('id',id);
            fm.append('title',title);
            fm.append('start_time',start_time);
            fm.append('end_time',end_time);
            fm.append('vote_limit',vote_limit);
            fm.append('total_limit',total_limit);
            fm.append('day_limit',day_limit);
            fm.append('content',content);

            if(pic_url !== '' && pic_url !== undefined){
                fm.append('pic_url',pic_url);
            }

            //异步提交
            $.ajax({
                type:"POST",
                url:'{:url("edit")}?id={$info.id}',
                data:fm,
                contentType:false,
                processData:false,
                success:function (res) {
                    if(res.code === 0){
                        layer.msg(res.msg,{icon:5,time:2000});
                    }else{
                        layer.msg(res.msg,{icon:6,time:2000});
                        location.replace("{:url('index')}");
                    }
                }
            });
        });

    });
</script>
</body>
</html>